const diseaseTypeDao = require('../dao/diseaseTypeDao')

// 添加
exports.add = async ctx => {
  let body = ctx.request.body
  console.log(body);
  
  const res = await diseaseTypeDao.create(body);
  ctx.success('创建成功')
}

// 获取全部
exports.getAll = async ctx => {
  let { p = 1,limit = 999 } = ctx.request.query
  let offset = (p - 1) * limit;
  let body = {
    offset:offset,
    limit:Number(limit)
  }
  const res = await diseaseTypeDao.findAll(body);
  ctx.success('',res)
}

// 删除某条数据
exports.del = async ctx => {
  let { id } = ctx.request.query
  const res = await diseaseTypeDao.delById(id);
  ctx.success('删除成功')
}

// 修改某条数据
exports.upd = async ctx => {
  let body = ctx.request.body
  const res = await diseaseTypeDao.upd(body);
  ctx.success('修改成功')
}

// 获取疾病种类(按类型、按部位、按科室)
exports.getDiseaseClass = async ctx => {
  let { DiseaseType } = ctx.request.query
  const res = await diseaseTypeDao.getByClass(DiseaseType);
  ctx.success('',res)
}